package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.RecordOfUserLs;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.RecordOfUserLsService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 recordOfUserLsController
//@RequestMapping("/recordOfUserLsController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /recordOfUserLsController
public class RecordOfUserLsController {
	@Resource
    RecordOfUserLsService recordOfUserLsService;

	@GetMapping("/getAllrecordOfUserLs")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<RecordOfUserLs> getAllRecordOfUserLs() throws Exception{
    	System.out.println("查询全部用户点赞方案记录");
    	return recordOfUserLsService.getAllRecordOfUserLss();
    }

	@PostMapping("/addrecordOfUserLs")
	@ResponseBody
	public DTO<RecordOfUserLs> addRecordOfUserLs(@RequestBody RecordOfUserLs recordOfUserLs) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加用户点赞方案记录成功");
		return recordOfUserLsService.addRecordOfUserLs(recordOfUserLs);
	}
	@DeleteMapping("/deleterecordOfUserLs/{rnoulsno}")
	@ResponseBody
    public DTO<RecordOfUserLs> deleteRecordOfUserLsByRnoulsno(@RequestBody @PathVariable("rnoulsno") String rnoulsno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(rnoulsno+"删除用户点赞方案记录成功");
    	return recordOfUserLsService.deleteRecordOfUserLsByRnoulsno(rnoulsno);
    }

	@GetMapping("/recordOfUserLsBy/{rnoulsno}")
	@ResponseBody
	public DTO<RecordOfUserLs> getRecordOfUserLsByRnoulsno(@PathVariable("rnoulsno") String rnoulsno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(rnoulsno+"根据主键查询用户点赞方案记录成功");
		return recordOfUserLsService.getRecordOfUserLsByRnoulsno(rnoulsno);
	}

	@PatchMapping("/updaterecordOfUserLs")
	@ResponseBody
	public DTO<RecordOfUserLs> updateRecordOfUserLsByRnoulsno(@RequestBody RecordOfUserLs recordOfUserLs) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改用户点赞方案记录成功");
		System.out.println(recordOfUserLs);
		return recordOfUserLsService.updateRecordOfUserLsByRnoulsno(recordOfUserLs);
	}

	@RequestMapping("/recordOfUserLs/pageInfo")
	@ResponseBody
	public DTO<RecordOfUserLs> getRecordOfUserLsByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return recordOfUserLsService.getRecordOfUserLsByPage(pageInfo);
	}

}
